package com.songcha.library_common.util


class AlgorithmUtil {
    companion object{

        @JvmStatic
        fun formatStyleFloatArray(array:FloatArray):FloatArray{
            if(array.size==4) return array
            val r=FloatArray(4)

            if(array.size==1){
                for( i in 0 until 4){
                    r[i]=array[0]
                }
            } else if(array.size==2){
                r[0]=array[0]
                r[2]=array[0]
                r[1]=array[1]
                r[3]=array[1]

            }else{
                for( i in 0 until 4){
                    r[i]=array[0]
                }
            }
            return r

        }

        @JvmStatic
        fun formatRadiiFloatArray(r: FloatArray):FloatArray{
            val radii= FloatArray(8)
            for( i in 0 until 4){
                radii[i*2]=r[i]
                radii[i*2+1]=r[i]
            }
            return radii
        }

        @JvmStatic
        fun <T> bubbleSort(arr:Array<T>,block:(T,T)->Boolean){
            val n = arr.size
            var swapped = false
            for(i in 0 until n-1){
                swapped = false
                for(j in 0 until n-i-1){
                    if(block(arr[j],arr[j+1])){
                        val tmp = arr[j]
                        arr[j] = arr[j+1]
                        arr[j+1] = tmp
                        swapped = true
                    }
                }
                if (!swapped)
                    break
            }
        }

        @JvmStatic
        fun <T> bubbleSort(list:MutableList<T>,block:(T,T)->Boolean){
            val n = list.size
            var swapped = false
            for(i in 0 until n-1){
                swapped = false
                for(j in 0 until n-i-1){
                    if(block(list[j],list[j+1])){
                        val tmp = list[j]
                        list[j] = list[j+1]
                        list[j+1] = tmp
                        swapped = true
                    }
                }
                if (!swapped)
                    break
            }
        }

    }
}